export const paperTypes = {
  A3: {
    width: 420,
    height: 296.6,
  },
  A4: {
    width: 210,
    height: 297,
  },
  A5: {
    width: 210,
    height: 147.6,
  },
  B3: {
    width: 500,
    height: 352.6,
  },
  B4: {
    width: 250,
    height: 352.6,
  },
  B5: {
    width: 250,
    height: 175.6,
  },
};

import { hiprint } from "vue-plugin-hiprint";
// 自定义设计元素1
export const aProvider = function (ops) {
  var addElementTypes = function (context) {
    context.removePrintElementTypes(ops.type);
    let data = ops.data || [];
    let arr = [];
    for (let i = 0; i < data?.length; i++) {
      let elements = [];
      for (let j = 0; j < data[i]?.elements?.length; j++) {
        switch (data[i]?.elements[j]?.element_type) {
          case "text":
            elements.push({
              tid: data[i]?.elements[j]?.id + ops.type,
              title: data[i]?.elements[j]?.element_name,
              data: "",
              type: data[i]?.elements[j]?.element_type,
              options: Object.assign({}, data[i]?.elements[j]?.options, {
                field: data[i]?.elements[j]?.label,
              }),
            });
            break;
          case "image":
            elements.push({
              tid: data[i]?.elements[j]?.id + ops.type,
              title: data[i]?.elements[j]?.element_name,
              data: data[i]?.elements[j]?.element_name.value,
              type: data[i]?.elements[j]?.element_type,
              options: Object.assign({}, data[i]?.elements[j]?.options, {
                field: data[i]?.elements[j]?.label,
              }),
            });
            break;
          case "table":
            elements.push({
              tid: data[i]?.elements[j]?.id + ops.type,
              title: data[i]?.elements[j]?.element_name,
              type: data[i]?.elements[j]?.element_type,
              options:{
                tableHeaderRepeat: 'first',
                tableFooterRepeat: 'last',
                fields: data[i]?.elements[j]?.custom,
                field: data[i]?.elements[j]?.label,
              },
              columns: [data[i]?.elements[j]?.options],
              editable: true,
              columnDisplayEditable: true, //列显示是否能编辑
              columnDisplayIndexEditable: true, //列顺序显示是否能编辑
              columnTitleEditable: true, //列标题是否能编辑
            });
            break;
          default:
            elements.push({
              tid: data[i]?.elements[j]?.id + ops.type,
              title: data[i]?.elements[j]?.element_name,
              type: data[i]?.elements[j]?.element_type,
            });
            break;
        }
      }
      arr.push(
        new hiprint.PrintElementTypeGroup(data[i].group_name_cn, elements)
      );
    }
    context.addPrintElementTypes(
      ops.type,
      arr
    );
  };
  return {
    addElementTypes: addElementTypes,
  };
};

export const modeDesign = [
  {
    name: "A设计",
    value: "aProviderModule",
    type: 1,
    f: (val) => aProvider({ data: val, type: "aProviderModule" }),
  },
  {
    name: "B设计",
    value: "bProviderModule",
    type: 2,
    f: (val) => aProvider({ data: val, type: "bProviderModule" }),
  },
];
